<template>

    <div class="second_block" v-if="visible" :style="productPageSize">
<!--      <div style="text-align: center;">-->
<!--        <img src="/static/logo.png" style="width: 80px;height: 75px">-->
<!--      </div>-->
<!--      <el-divider></el-divider>-->
      <div style="font-size: 15px;text-align: center;font-weight: bold;color: #000000;line-height: 30px;">{{script_1}}</div>
<!--      <br>-->
<!--      <div style="font-size: 15px;text-align: center;font-weight: bold;color: #000000;line-height: 30px;">{{script_2}}</div>-->
      <div class="body">
        <br>
        <el-form
          :model="form"
          ref="form"
          :rules="rules">
          <el-form-item
            class="prodcutItem"
            prop="name">
<!--                          <span style="color: #000;font-weight: 700;">Name:</span>-->
            <el-input
              :maxlength="25"
              v-model="form.order_name"
              placeholder="Enter Your Name"
              clearable/>
          </el-form-item>
          <el-form-item
            class="prodcutItem"
            prop="email">
<!--                          <span style="color: #000;font-weight: 700;">Email:</span>-->
            <el-input
              :maxlength="40"
              v-model="form.order_email"
              placeholder="Enter Your Email"
              clearable/>
          </el-form-item>
          <el-form-item
            class="prodcutItem"
            v-if="phone_require==1"
            prop="phone">
            <!--              <span style="color: #000;font-weight: 700;">Phone:</span>-->
            <el-input
              :maxlength="20"
              v-model="form.phone"
              placeholder="Enter Your Phone"
              clearable/>
          </el-form-item>
          <el-form-item
            class="prodcutItem"
            prop="address">
            <!--              <span style="color: #000;font-weight: 700;">Address:</span>-->
            <el-input
              :maxlength="50"
              v-model="form.address"
              placeholder="Enter Your Address"
              clearable/>
          </el-form-item>
          <el-form-item
            class="prodcutItem"
            prop="state">
            <!--              <span style="color: #000;font-weight: 700;">State/Region:</span>-->
            <el-input
              :maxlength="30"
              v-model="form.state"
              placeholder="Enter Your State/Region"
              clearable/>
          </el-form-item>
          <el-form-item
            class="prodcutItem"
            prop="postal_code">
            <!--              <span style="color: #000;font-weight: 700;">Postal Code:</span>-->
            <el-input
              :maxlength="30"
              v-model="form.postal_code"
              placeholder="Enter Your Postal Code"
              clearable/>
          </el-form-item>
          <el-form-item
            class="prodcutItem"
            prop="country">
            <!--              <span style="color: #000;font-weight: 700;">Country:</span>-->
            <el-input
              :maxlength="30"
              v-model="form.country"
              placeholder="Enter Your Country"
              clearable/>
          </el-form-item>
          <el-form-item
            class="prodcutItem"
            prop="city">
            <!--              <span style="color: #000;font-weight: 700;">City:</span>-->
            <el-input
              :maxlength="20"
              v-model="form.city"
              placeholder="Enter Your City"
              clearable/>
          </el-form-item>

        </el-form>
        <br/>
        <div style="text-align: center">
          <el-button  style="background-color: #536cec" :loading="loading" @click="doConfirmProduct" ><span style="color: white">Confirm</span></el-button>
        </div>
        <br/>
      </div>
    </div>
</template>

<script>
export default {
  name: "product-page",
  props: {
    // 弹窗是否打开
    visible: Boolean,
    data: Object,
  },
  data() {
    return {
      // 表单数据
      form: this.data,
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      script_1:'',
      script_2:'',
      phone_require:1,
      productPageSize:'',
    };
  },
  computed: {
    // 表单验证规则
    rules() {
      return {
        // order_name: [
        //   {required: true, message: 'Enter Your Name...', type: 'string', trigger: 'blur'}
        // ],
        // order_email: [
        //   {required: true, message: 'Enter Your Email...', type: 'string', trigger: 'blur'}
        // ],
        // phone: [
        //   {required: true, message: 'Enter Your Phone...', type: 'string', trigger: 'blur'}
        // ],
        // address: [
        //   {required: true, message: 'Enter Your Address...', type: 'string', trigger: 'blur'}
        // ],
        // state: [
        //   {required: true, message: 'Enter Your State/Region...', type: 'string', trigger: 'blur'}
        // ],
        // postal_code: [
        //   {required: true, message: 'Enter Your Postal Code...', type: 'string', trigger: 'blur'}
        // ],
        // country: [
        //   {required: true, message: 'Enter Your Country...', type: 'string', trigger: 'blur'}
        // ],
        // city: [
        //   {required: true, message: 'Enter Your City...', type: 'string', trigger: 'blur'}
        // ],
      };
    },
    // 当前语言
    language() {
      return this.$i18n.locale;
    }
  },
  mounted () {
    // 根据不同路由跳转不同页面
    if (this._isMobile()) {
      this.productPageSize = 'height: calc(100vw + 135px)';
    } else {
      this.productPageSize = 'height: calc(100vw - 990px);width:calc(100vw - 990px);';
    }
  },
  methods : {
    // 判断是否是手机端，如果是，返回true
    _isMobile () {
      let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
      return flag
    },
    setForm(form)
    {
      this.form = form;
      this.form.order_name = form.name;
      this.form.order_email = form.email;
    },
    setBuyerConfig(data){
      this.script_1 = data.gift_product_page_script.script_1;
      this.script_2 = data.gift_product_page_script.script_2;
      this.phone_require = data.phone_require;
    },
    setProductConfig(data){
      this.script_1 = data.gift_product_page_script.script_1;
      this.script_2 = data.gift_product_page_script.script_2;
    },
    //关闭页面
    handleClose(done) {
      done();
      this.$emit('handleClose');
    },
    //跳转结束流程
    doConfirmProduct()
    {
      this.$refs['form'].validate((valid) => {
        if (!valid) {
          return false;
        }else{
          this.loading = true;
          this.$emit('doConfirmProduct',this.form);
        }
      });
    }
  }
}
</script>

<style scoped>

@media screen and (max-width: 750px) {
  .body {
    width: 96%;
    margin: 0 auto;
    background-color: white;
  }
}

@media screen and (min-width: 750px) {
  .body {
    margin: 0 auto;
    width: 50%;
  }
}
::v-deep .el-rate__icon{
  font-size: 30px;
}



::v-deep .el-form-item{
  margin-bottom: 1px;
}

::v-deep .prodcutItem{
  margin-bottom: 2%
}

</style>
